<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let xhr = new XMLHttpRequest;  //创建ajax
        document.cookie = 'name=zfpx';
        xhr.withCredentials = true;
        xhr.open('PUT','http://localhost:4000/getData',true);  //开启  true表示是否异步
        xhr.setRequestHeader('name','zfpx')
        xhr.onreadystatechange = function(){     //每当readyState改变时，就会触发onreadystatechange事件readyState属性存有XMLHttpRequest的状态信息。
            if(xhr.readyState === 4){   //4: 请求已完成，且响应已就绪
                if(xhr.status>=200 && xhr.status < 300 || xhr.status === 304){  //2: 请求已接收   304缓存
                    console.log(xhr.response);   //打印请求回来的东西
                    console.log(xhr.getResponseHeader('name'));
                }
            }
        }
        xhr.send();

    </script>
</body>
</html>